package com.svs.web.controller.project;

import java.util.List;

import com.svs.common.utils.ExcelUtil;
import com.svs.project.domain.ProLine;
import com.svs.project.service.ProLineService;
import com.svs.system.domain.SysPost;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.svs.common.annotation.Log;
import com.svs.common.enums.BusinessType;
import com.svs.project.domain.Counter;
import com.svs.project.service.CounterService;
import com.svs.framework.web.BaseController;
import com.svs.framework.web.page.TableDataInfo;
import com.svs.common.base.AjaxResult;

/**
 * 生产线计数详情 信息操作处理
 * 
 * @author 杜建桥
 * @date 2025-06-20
 */
@Controller
@RequestMapping("/project/counter")
public class CounterController extends BaseController {

    private String prefix = "project/counter";
	
	@Autowired
	private CounterService counterService;

	@RequiresPermissions("project:counter:view")
	@GetMapping()
	public String counter() {
	    return prefix + "/counterList";
	}

	/**
	 * 查询生产线计数详情列表
	 */
	@RequiresPermissions("project:counter:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Counter counter) {
		startPage();
        List<Counter> list = counterService.selectAllList(counter);
		return getDataTable(list);
	}

	/**
	 * 新增生产线计数详情
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/addCounter";
	}

	/**
	 * 新增保存生产线计数详情
	 */
	@RequiresPermissions("project:counter:add")
	@Log(title = "生产线计数详情", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Counter counter) {
		String code = counter.getCode();
		Integer num = counterService.selectByCode(code);
		counter.setNum(num + counter.getNum2());
		return toAjax(counterService.save(counter));
	}

	/**
	 * 修改生产线计数详情
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		Counter counter = counterService.selectByPrimaryKey(id);
		mmap.put("counter", counter);
	    return prefix + "/editCounter";
	}

	/**
	 * 修改保存生产线计数详情
	 */
	@RequiresPermissions("project:counter:edit")
	@Log(title = "生产线计数详情", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Counter counter) {

		return toAjax(counterService.update(counter));
	}

	/**
	 * 删除生产线计数详情
	 */
	@RequiresPermissions("project:counter:remove")
	@Log(title = "生产线计数详情", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String[] ids) {
		return toAjax(counterService.deleteByPrimaryKeys(ids));
	}


	@Log(title = "生产线计数详情", businessType = BusinessType.EXPORT)
	@RequiresPermissions("project:counter:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Counter counter) {
		List<Counter> list = counterService.selectAllList(counter);
		ExcelUtil<Counter> util = new ExcelUtil<>(Counter.class);
		return util.exportExcel(list, "counter");
	}
}
